//
//  DYJMovieTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJMovieTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "RBCountDownView.h"
#import "Masonry.h"

@interface DYJMovieTableViewCell ()<RBCountDownViewDelegate>

@end

@implementation DYJMovieTableViewCell {

    RBCountDownView *rb2;
    UILabel *countLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.movieImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_movieImageView];
        
        self.scoreView = [[DYJMovieScoreView alloc] init];
        [self.contentView addSubview:_scoreView];
        
        
        self.scoreLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_scoreLabel];
        
        
        rb2 = [[RBCountDownView alloc] initWithLabelMode:RBCountDownModeFull];
        rb2.delegate = self;
        [self.contentView addSubview:rb2];
        
        [rb2 setTotalTimeInterval:23000];
        [self.contentView bringSubviewToFront:rb2];
        
        
        
        countLabel = [[UILabel alloc] init];
        countLabel.text = @"距离分数公布还有:";
        countLabel.textColor = [UIColor colorWithRed:0.23 green:0.22 blue:0.22 alpha:1.00];
        countLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:countLabel];
        

    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.movieImageView.frame = CGRectMake(0, 0, ScreenWidth, self.frame.size.height - 4);
    self.scoreView.frame = CGRectMake(self.frame.size.width - 90, self.frame.size.height - 104, 120, 100);
    if (_scoreView.scoreLabel.text == nil) {
        self.scoreView.scoreLineImageView.hidden = YES;
        rb2.hidden = NO;
        countLabel.hidden = NO;
    }
    else
    {
        self.scoreView.scoreLineImageView.hidden = NO;
        rb2.hidden = YES;
        countLabel.hidden = YES;
    }
    [self.scoreLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-5);
        make.bottom.equalTo(-5);
        make.height.equalTo(50);
        make.width.equalTo(100);
    }];
    
    [rb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(15);
        make.bottom.equalTo(self.contentView).offset(5);
        make.height.equalTo(50);
        make.width.equalTo(100);
    }];
    
    [countLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(rb2.left).offset(12);
        make.bottom.equalTo(rb2);
        make.height.equalTo(50);
        make.width.equalTo(100);
    }];

}
- (void)setModel:(DYJMovieListModel *)model
{
    if (_model != model) {
        _model = model;
        self.scoreView.scoreLabel.text = model.score;
        [self.movieImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"xph"]];
        self.movieImageView.contentMode = UIViewContentModeScaleAspectFill;
        
        if (model.score == nil) {
            
                    }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)RBCountDownViewDidStopCounting:(RBCountDownView *)countDownView
{
    NSLog(@"<< %p >> counting down finished!", countDownView);
}

@end
